#pragma once
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string>

class Inet_Addr
{
public:
    Inet_Addr(struct sockaddr_in &addr)
    {
        ip = inet_ntoa(addr.sin_addr); // 将sockaddr_in中4字节的ip转换出来
        port = ntohs(addr.sin_port);   // 网络字节序转主机字节序
    }

    std::string Getip()
    {
        return ip;
    }

    uint16_t Getport()
    {
        return port;
    }

    std::string PrintDebug()
    {
        std::string info;
        info += ip;
        info += ":";
        info += std::to_string(port);
        return info;
    }

private:
    std::string ip;
    u_int16_t port;
};
